package com.shiguiwu.springmybatis.designpattern.prototype;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: 原型模式测试
 * 定义：用原型实例指定创建对象的种类，并且通过拷贝这些原型创建新的对象。
 * 同时还可以破坏单列
 * @author: stone
 * @date: Created by 2021/2/22 20:06
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.prototype
 */
public class PrototypeTests {

    public static void main(String[] args) throws CloneNotSupportedException {
        Pig pig = new Pig("小猪佩奇", 780, new Date(66L));
        System.out.println(pig.toString() + pig.hashCode());

        Pig pig1 = (Pig) pig.clone();
        System.out.println(pig1 == pig);
        //深克隆
        System.out.println(pig1.getBirthday() == pig.getBirthday());

        HashMap<String, Object> map = new HashMap<>();
        map.put("shigiwu", "haha");
        map.put("1", 12);
        System.out.println(map);

        HashMap<String, Object> mapClone = (HashMap<String, Object>) map.clone();
        System.out.println(mapClone);
    }
}
